package com.example.keli.ui;

import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.TextUtils;

import com.example.keli.MainActivity;
import com.example.keli.R;
import com.example.keli.base.AppConfig;
import com.example.keli.base.BaseActivity;
import com.example.keli.base.utils.GlobalStatusBarUtil;
import com.example.keli.base.utils.SPUtils;
import com.example.keli.base.utils.ThreadUtils;
import com.example.keli.ui.register.LoginAndRegisterActivity;


/**
 * Created by Tony on 2018/1/16.
 */

public class SplashActivity extends BaseActivity {
    private CountDownTimer mDownTimer;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        if (!isTaskRoot()) {
            finish();
            return;
        }
        super.onCreate(savedInstanceState);
    }

    @Override
    protected int layoutId() {
        GlobalStatusBarUtil.setUpStatusBar(this, android.R.color.transparent, false);
        return R.layout.activity_app_splash_layout;
    }

    @Override
    protected void bindData() {
        mDownTimer = new CountDownTimer(1 * 1000, 1000) {
            @Override
            public void onTick(long l) {
            }

            @Override
            public void onFinish() {
                ThreadUtils.runOnSubThread(new Runnable() {
                    @Override
                    public void run() {
                        String accountString = (String) SPUtils.get(SplashActivity.this, AppConfig.PERSONAL_DATA, "");
                        if (TextUtils.isEmpty(accountString)) {
                            toActivity(LoginAndRegisterActivity.class);
                        } else {
                            toActivity(MainActivity.class);
                        }
                        finish();
                    }
                });
            }
        };
        mDownTimer.start();
    }

}
